<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">

		<title>ERROR-INFO</title>
		<meta name="keywords" content="ERROR-INFO">
		<meta name="description" content="ERROR-INFO">

		<link href="../css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
		<link href="../css/font-awesome.css?v=4.4.0" rel="stylesheet">
		
		<link href="../css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    
		<link href="../css/animate.css" rel="stylesheet">
		<link href="../css/style.css?v=4.1.0" rel="stylesheet">

		<!-- 表格 -->
		<link href="../css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
	</head>

	<body class="gray-bg">
		<div class="wrapper wrapper-content animated fadeInRight">

			<div class="row">
				<div class="col-sm-12">
					<div class="ibox float-e-margins">
						<div class="ibox-title">
							<h5><i class="fa fa-table"></i> 实例列表  <font color="#DCDCDC"> (点击行查看实例详情)</font></h5>
							<div class="ibox-tools">
								<a class="collapse-link"> <i class="fa fa-chevron-up"></i>
								</a>
								<a class="dropdown-toggle" data-toggle="dropdown" href="rpc_list.html#"> <i class="fa fa-wrench"></i>
								</a>
								<ul class="dropdown-menu dropdown-user">
									<li>
										<a href="rpc_list.html#">选项1</a>
									</li>
									<li>
										<a href="rpc_list.html#">选项2</a>
									</li>
								</ul>

							</div>
						</div>
						<div class="ibox-content">
							<table id="agentIds_tb" class="table table-striped table-bordered table-hover dataTables-example">
							</table>
						</div>

					</div>
				</div>
			</div>

			<div class="row">
				<div class="col-sm-12">
					<div class="ibox float-e-margins">
						<div class="ibox-title">
							<h5>
							<i class="fa fa-table"></i> 实例详细信息
						</h5>
							<div class="ibox-tools">
								<a class="collapse-link"> <i class="fa fa-chevron-up"></i>
								</a>
								<a class="dropdown-toggle" data-toggle="dropdown" href="rpc_list.html#"> <i class="fa fa-wrench"></i>
								</a>
								<ul class="dropdown-menu dropdown-user">
									<li>
										<a href="rpc_list.html#">选项1</a>
									</li>
									<li>
										<a href="rpc_list.html#">选项2</a>
									</li>
								</ul>

							</div>
						</div>

						<div class="ibox-content">
							<table id="infomation_tb" data-toggle="table"  data-show-header="false">

							</table>
						</div>

					</div>

				</div>

			</div>
			<div class="row" id="infomation"></div>

			<!-- 全局js -->
			<script src="../js/jquery.min.js?v=2.1.4"></script>
			<script src="../js/bootstrap.min.js?v=3.3.6"></script>

			<!-- 表格 -->
			<script src="../js/plugins/dataTables/jquery.dataTables.js"></script>
			<script src="../js/plugins/dataTables/dataTables.bootstrap.js"></script>
			
			<script src="../js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    		<script src="../js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
    		<script src="../js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

			<!-- 自定义js -->
			<script src="../js/content.js?v=1.0.0"></script>
			
			<script src="../js/jquery.i18n.properties-min-1.0.9.js"></script>

			<!-- 时间框 -->
			<script src="../js/mine/time.js"></script>
			<!--	<script src="../js/app.js"></script>-->
			<script src="../js/angular.js"></script>
			<script src="../js/server-map-dao.service.js"></script>

			<script>
			
//			var preUrl = "http://127.0.0.1:8041";
//			var preUrl = "http://10.145.196.107:8041";
			var preUrl = getUrl();
			
			
			
			function  getUrl(){  
				var url = "";
			    jQuery.i18n.properties({// 加载properties文件  
			    name:'ipAndPort', // properties文件名称  
			    path:'../properties/', // properties文件路径  
			    mode:'map', // 用 Map 的方式使用资源文件中的值  
			    callback: function() {// 加载成功后设置显示内容  
//			       //其中isp_index为properties文件中需要查找到的数据的key值  
			    	url = $.i18n.prop("url");
			    	
			    	
			    }
			    });
			    
			   
			    return url;
			} 
			
				//获取地址栏参数，name:参数名称
				function getRequest() {
					var url = window.location.search; //获取url中"?"符后的字串
					var theRequest = new Object();
					if(url.indexOf("?") != -1) {
						var str = url.substr(1);
						strs = str.split("&");
						for(var i = 0; i < strs.length; i++) {

							theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);

						}
					}
					return theRequest;
				}
				var info;
				var rpcListFlag = false;

				window.onload = function() {

					var applicationName = getRequest().applicationName;
					var startTimestamp = getRequest().startTimestamp;
					var endTimestamp = getRequest().endTimestamp;
					var limit = getRequest().limit;
						$("#infomation_tb").empty();

					//								$.get("http://10.145.196.107:8041/transactionInfoDetail", {
//					$.get("http://localhost:8041/showAgentInfo", {
					$.get(preUrl + "/showAgentInfo", {
							applicationName: applicationName,
							startTimestamp: startTimestamp,
							endTimestamp: endTimestamp,
							limit: limit
						},
						function(data) {
							info = data;

							/*if(rpcListFlag == true) {
								$("#agentIds_tb").dataTable().fnDestroy();
							}*/
						

							$("#agentIds_tb").empty();
							$("#agentIds_tb").append($("<thead><tr><th>序号</th><th>服务名</th><th>实例名</th><th>IP</th><th>PID</th><th>开始时间</th></tr></thead><tbody>"));
							$.each(data, function(i, item) {

								td = $("<tr onclick=\"infomation(&quot;" + item.agentId + "&quot;)\"><td>" + (i + 1) +
									'</td><td >' + data[i].applicationName +
									"</td><td>" + item.agentId + "</td><td>" + data[i].ip + "</td><td>" + data[i].pid + "</td><td><i class='fa fa-clock-o'></i> " + getFormatDate(data[i].startTimestamp) +

									"</td></tr>");
								$("#agentIds_tb").append(td);

							});
							$("#agentIds_tb").append("</tbody>");
							$('#agentIds_tb').dataTable();
							rpcListFlag = true;

						});

				}
				var serverMetaData;

				function infomation(agentId) {
					$.each(info, function(i, item) {
						if(agentId == item.agentId) {

							serverMetaData = item.serverMetaData;

							

							$("#infomation_tb").empty();
							
								
								tr1 = $("<tr><td align='right'>服务名称 </td><td>" + item.applicationName + "</td><td align='right'>实例版本</td><td>" + item.agentVersion + "</td></tr>");
								tr2 = $("<tr><td align='right'>实例名 </td><td>" + item.agentId + "</td><td align='right'>PID</td><td>" + item.pid + "</td></tr>");
								tr3 = $("<tr><td align='right'>主机名 </td><td>" + item.hostName + "</td><td align='right'>JVM (GC Type)</td><td>" + item.jvmInfo.jvmVersion + "(" + item.jvmInfo.gcTypeName + ")</td></tr>");
								tr4 = $("<tr><td align='right'>IP </td><td>" + item.ip + "</td><td align='right'>开始时间</td><td>" + getFormatDate(item.startTimestamp) + "</td></tr>");
								tr5 = $("<tr><td align='right'>服务类型 </td><td>SPRING_BOOT(" + item.serverMetaData.serverInfo + ")&nbsp;&nbsp;&nbsp;<a href='#infomation'><button class='btn-white'  onclick='showServerMetaData()'>详情</button></a></td><td align='right'>状态</td><td>" + item.status + "</td></tr>");
								
								$("#infomation_tb").append(tr1);
								$("#infomation_tb").append(tr2);
								$("#infomation_tb").append(tr3);
								$("#infomation_tb").append(tr4);
								$("#infomation_tb").append(tr5);

							
//							$("#infomation_tb").append("</tbody>");
							

						}

					});
				}

				var flag = true;

				function showServerMetaData() {

					if(flag) {
						$("#infomation").append($('<div class="col-sm-9" id=""><div class="ibox-content">' +
							'<div class="row"><div class="col-xs-9 "><h4>服务信息 :' + serverMetaData.serverInfo + '</h4></div></div>' +
							'<div class="ibox-content" id="vmargs"></div>' +
							'<div class="ibox-content"><div class="row"><div class="col-xs-9 "><h4>服务 :' + serverMetaData.serviceInfos[0].serviceName + '</h4></div></div></div>' +
							'</div></div>'));

						$.each(serverMetaData.vmArgs, function(i, item) {
							if(i == 0) {
								$("#vmargs").append($('<div class="row"><div><h4>JVM 参数 :' + item + '</h4></div></div>'));

							} else {
								$("#vmargs").append($('<div class="row"><div><h4>&nbsp;&nbsp; &nbsp;&nbsp; :' + item + '</h4></div></div>'));

							}

						});
						flag = false;
					} else {
						$("#infomation").html("");
						flag = true;
					}

				}
			</script>

	</body>

</html>